/**
 * Copyright (c) CSIRO Australia, 2009
 *
 * @author $Author: jia020 $
 * @version $Id: WorkflowsPanel.java 643 2009-05-20 00:20:55Z jia020 $
 */
package au.csiro.nt.pdsp.client;

import com.gwtext.client.core.EventObject;
import com.gwtext.client.widgets.Button;
import com.gwtext.client.widgets.Panel;
import com.gwtext.client.widgets.Toolbar;
import com.gwtext.client.widgets.ToolbarButton;
import com.gwtext.client.widgets.event.ButtonListenerAdapter;
import com.gwtext.client.widgets.layout.FitLayout;

/**
 * Class to create a panel for showing Workflows result to 3party user.
 */
public class WorkflowsPanel extends Panel {
	private String xmlData = null;
	private EventHandler eventHandler = null;

	/**
	 * Constructor for WorkflowsPanel
	 * 
	 * @param eventHandler
	 *          for callback.
	 * @param xmlData
	 *          xml formated workflows data.
	 */
	public WorkflowsPanel(EventHandler eventHandler, String xmlData) {
		super();
		this.eventHandler = eventHandler;
		this.xmlData = xmlData;
		this.setBorder(false);
		this.setPaddings(5);
		this.setLayout(new FitLayout());
		DynamicGrid grid = new DynamicGrid(xmlData);
		;

		Toolbar toolbar = new Toolbar();
		ToolbarButton button = new ToolbarButton("Show in google map",
				new ButtonListenerAdapter() {
					public void onClick(Button button, EventObject e) {
						loadGoogleMap();
					}
				});
		toolbar.addButton(button);
		this.add(grid);
		this.add(toolbar);
	}

	private void loadGoogleMap() {
		eventHandler.processEvent(PdspConst.EVENT_SHOW_GOOGLEMAP, xmlData);
	}
}
